/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.atp.agencia.ui.controle.aluguel;

import br.com.atp.agencia.util.DateUtil;
import java.util.Date;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Afonso
 */
public abstract class JIFControlaAluguel extends javax.swing.JInternalFrame {

    /**
     * Creates new form JIFControlaAluguel
     */
    boolean modoEntrada;
    private MaskFormatter mf1;

    public JIFControlaAluguel(boolean modo) {
        initComponents();
        initObjects();
        modoEntrada = modo;
        validaModo();
        ocultaCampos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTFNome = new javax.swing.JTextField();
        jFTCpf = new javax.swing.JFormattedTextField();
        jTFNumPessoas = new javax.swing.JTextField();
        jFTDataEntrada = new javax.swing.JFormattedTextField();
        jLDataSaida = new javax.swing.JLabel();
        jFTDataSaida = new javax.swing.JFormattedTextField();
        jLCamaExtra = new javax.swing.JLabel();
        jTFCamaExtra = new javax.swing.JTextField();
        jBCalculaTotalGeral = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jBCancel = new javax.swing.JButton();
        jLTotalGeral = new javax.swing.JLabel();
        jTFTotalGeral = new javax.swing.JTextField();
        jBRegistrarEntrada = new javax.swing.JButton();
        jBRegistrarSaida = new javax.swing.JButton();

        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel1.setText("Nome:");

        jLabel2.setText("CPF:");

        jLabel3.setText("Numero de Pessoas");

        jLabel4.setText("Data da Entrada");

        jFTDataEntrada.setToolTipText("M/dd/yyyy HH:mm");

        jLDataSaida.setText("Data Saida");

        jFTDataSaida.setToolTipText("M/dd/yyyy HH:mm");

        jLCamaExtra.setText("Camas Extras");

        jBCalculaTotalGeral.setText("Calcula Total Geral");
        jBCalculaTotalGeral.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCalculaTotalGeralActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLDataSaida)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel1)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTFNome, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jFTDataSaida, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                            .addComponent(jFTDataEntrada, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTFNumPessoas, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jFTCpf, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLCamaExtra)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTFCamaExtra, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(128, 128, 128))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jBCalculaTotalGeral)
                .addGap(53, 53, 53))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jFTDataSaida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTFNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jFTCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTFNumPessoas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLCamaExtra)
                            .addComponent(jTFCamaExtra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jFTDataEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLDataSaida)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(jBCalculaTotalGeral)
                .addContainerGap())
        );

        jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jBCancel.setText("Cancela");
        jBCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelActionPerformed(evt);
            }
        });

        jLTotalGeral.setText("Total Geral:");

        jBRegistrarEntrada.setText("Registrar Entrada");
        jBRegistrarEntrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRegistrarEntradaActionPerformed(evt);
            }
        });

        jBRegistrarSaida.setText("Registrar Saida");
        jBRegistrarSaida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRegistrarSaidaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 149, Short.MAX_VALUE)
                .addComponent(jBRegistrarSaida)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBRegistrarEntrada)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBCancel))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLTotalGeral)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTFTotalGeral, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLTotalGeral)
                    .addComponent(jTFTotalGeral, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCancel)
                    .addComponent(jBRegistrarEntrada)
                    .addComponent(jBRegistrarSaida))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 460, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jBCancelActionPerformed

    private void jBRegistrarEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRegistrarEntradaActionPerformed
        // TODO add your handling code here:
        registraEntrada();
    }//GEN-LAST:event_jBRegistrarEntradaActionPerformed

    private void jBRegistrarSaidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRegistrarSaidaActionPerformed
        // TODO add your handling code here:
        registraSaida();
    }//GEN-LAST:event_jBRegistrarSaidaActionPerformed

    private void jBCalculaTotalGeralActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCalculaTotalGeralActionPerformed
        // TODO add your handling code here:
        calculaTotalGeral();
    }//GEN-LAST:event_jBCalculaTotalGeralActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCalculaTotalGeral;
    private javax.swing.JButton jBCancel;
    private javax.swing.JButton jBRegistrarEntrada;
    private javax.swing.JButton jBRegistrarSaida;
    protected javax.swing.JFormattedTextField jFTCpf;
    protected javax.swing.JFormattedTextField jFTDataEntrada;
    protected javax.swing.JFormattedTextField jFTDataSaida;
    protected javax.swing.JLabel jLCamaExtra;
    protected javax.swing.JLabel jLDataSaida;
    protected javax.swing.JLabel jLTotalGeral;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    protected javax.swing.JTextField jTFCamaExtra;
    protected javax.swing.JTextField jTFNome;
    protected javax.swing.JTextField jTFNumPessoas;
    protected javax.swing.JTextField jTFTotalGeral;
    // End of variables declaration//GEN-END:variables

    private void validaModo() {
        if (verificaModo()) {
            jBRegistrarEntrada.setVisible(true);
            jBRegistrarSaida.setVisible(false);
            jTFTotalGeral.setVisible(false);
            jLTotalGeral.setVisible(false);
            jLDataSaida.setVisible(false);
            jFTDataSaida.setVisible(false);
            jFTDataEntrada.setEditable(true);
            jFTDataEntrada.setText(DateUtil.getStringFromDate(new Date(), DateUtil.formatoBR));
            jBCalculaTotalGeral.setVisible(false);
        } else {
            jBRegistrarEntrada.setVisible(false);
            jBRegistrarSaida.setVisible(true);
        }
    }

    public abstract void initLabels(); /*{
     jTFNome.setText(l1.getNome());
     jFTCpf.setText(l1.getCpf());
     jTFNumPessoas.setText(String.valueOf(a1.getNumPessoas()));
     jFTDataEntrada.setText(DateUtil.getStringFromDate(a1.getEntrada(), DateUtil.formatoBR));
     jTFTotalGeral.setText(String.valueOf(a1.getTotalDevido()));
     if (a1 instanceof Chale) {
     Chale c1 = (Chale) a1;
     jTFCamaExtra.setText(String.valueOf((c1.getNumPessoasExtras())));
     }
     }
     */


    public abstract void ocultaCampos();

    public abstract void registraEntrada();

    public abstract void registraSaida();

    public abstract void preencheDados();

    public abstract void initObjects();
    
    public abstract void calculaTotalGeral();

    protected boolean verificaModo() {
        return modoEntrada;
    }

}
